package com.itcast.rpc.client.order;

import com.itcast.rpc.client.order.pojo.Item;
import com.itcast.rpc.client.order.pojo.Order;
import com.itcast.rpc.client.order.service.OrderService;
import com.itcast.rpc.core.client.NettyRpcClient;
import com.itcast.rpc.core.client.response.BeanFactory;

import java.util.ArrayList;
import java.util.List;

public class ClientServer {
    
    public static void main(String[] args) {
        NettyRpcClient nettyClient = new NettyRpcClient();
        
        nettyClient.start("127.0.0.1", 5566);
        
        BeanFactory beanFactory = new BeanFactory(nettyClient);
        
        OrderService orderService = beanFactory.getBean(OrderService.class);
        
        List<Item> itemList = new ArrayList<>();
        Item item = new Item();
        item.setItemId(2001L);
        item.setPrice(100L);
        item.setTitle("铅笔");
        itemList.add(item);
        
        item = new Item();
        item.setItemId(2002L);
        item.setPrice(50L);
        item.setTitle("橡皮");
        itemList.add(item);
        
        for (int i = 0; i < 10; i++) {
            Order order = orderService.submitOrder(1001L, itemList);
            System.out.println("返回数据：" + order);
        }
        
        nettyClient.close();
        
    }
    
}